<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css"
      integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
<div class="row">
    <div class="col-md-4"></div>
    <div class="col-md-4"  style="margin-top:2%">
        <div class="form-group">
            <textarea type="text" class="form-control" disabled placeholder="重新添加ip时，旧ip地址会清空，仅限办公区域网络因断电等原因导致运营商重新分配IP地址时使用此功能，需要添加多个IP地址时，请使用英文逗号隔开"></textarea>
        </div>
        <div class="form-group">
            <label for="exampleInputEmail1">IP</label>
            <textarea type="text" class="form-control" name="ip" id="exampleInputEmail1" placeholder="请输入ip地址"></textarea>
        </div>
        <div class="form-group">
            <label for="exampleInputPassword1">密码</label>
            <input type="password" name="password" class="form-control" id="exampleInputPassword1"
                   placeholder="请输入密码">
        </div>
        <button type="submit" class="btn btn-primary" onclick="addIp()">提交</button>
    </div>
    <div class="col-md-4"></div>
</div>
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script>
    function addIp() {
        var formData = new FormData();
        formData.append('ip', $("textarea[name=ip]").val());
        formData.append('password', $("input[name=password]").val());
        formData.append('_token', $("input[name='_token']").val());
        $.ajax({
            url: '/addIp', // 服务器端处理文件上传的脚本URL
            type: 'POST',
            data: formData,
            contentType: false, // 告诉jQuery不要去设置Content-Type请求头
            processData: false, // 告诉jQuery不要处理发送的数据
            success: function (response) {
                if(response.code == -1) alert(response.message);
                else alert('ip添加成功');
                // window.location.href = '/admin/task/';
            },
            error: function (xhr, status, error) {
                $('#result').html('文件上传失败: ' + error); // 显示错误信息
            }
        });
    }
</script>
